package com.ants.boot.wx.controller;

import com.ants.boot.core.Response;
import com.ants.boot.core.security.user.LoginUser;
import com.ants.boot.model.BaseController;
import com.ants.boot.core.security.utils.SecurityUtils;
import com.ants.boot.wx.dto.selfset.WxEditAgeDto;
import com.ants.boot.wx.dto.selfset.WxEditEmailDto;
import com.ants.boot.wx.dto.selfset.WxEditNicknameDto;
import com.ants.boot.wx.dto.selfset.WxEditSexDto;
import com.ants.boot.wx.service.WxSelfSetService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author 蚂蚁会花呗
 * @date 2022/5/27 16:13
 * 个人设置
 */
@RestController
@RequestMapping("wx/selfset")
@Api(tags = "个人信息及设置")
public class WxSelfSetController extends BaseController {

    @Autowired
    private WxSelfSetService wxSelfSetService;

    /**
     * 获取个人信息
     * @return
     */
    @GetMapping("get_user")
    @ApiOperation(value="个人信息",notes="获取个人信息")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！",response = LoginUser.class)
    })
    public Response getUser(){
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return Response.okData(loginUser);
    }


    @PostMapping("edit_nickname")
    @ApiOperation(value = "更新昵称")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response editNickname(@RequestBody @Validated WxEditNicknameDto dto){
        boolean result = wxSelfSetService.editNickname(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

    @PostMapping("edit_sex")
    @ApiOperation(value = "更新性别")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response editSex(@RequestBody @Validated WxEditSexDto dto){
        boolean result = wxSelfSetService.editSex(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

    @PostMapping("edit_age")
    @ApiOperation(value = "更新年龄")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response editAge(@RequestBody @Validated WxEditAgeDto dto){
        boolean result = wxSelfSetService.editAge(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }



    @PostMapping("edit_email")
    @ApiOperation(value = "更新邮箱")
    @ApiResponses({
            @ApiResponse(code = 200,message = "操作成功！")
    })
    public Response editEmail(@RequestBody @Validated WxEditEmailDto dto){
        boolean result = wxSelfSetService.editEmail(dto);
        if (!result){
            return Response.fail();
        }
        return Response.ok();
    }

}
